﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using CMP.ERP.Model;
using CMP.ERP.BLL;
using System.Data;
using System.Data.SqlClient;


namespace CMP.ERP.Admin.Controllers
{
    public class LocalityController : Controller
    {
        //
        // GET: /Locality/
        LocalityBLL bll = new LocalityBLL();
        public ActionResult Locality_Show()
        {
            List<Province> list = new List<Province>();
            DataTable data = bll.GetLocality("0");
            foreach (DataRow item in data.Rows)
            {
                Province e = new Province();
                e.P_Id = Convert.ToInt32(item["P_Id"]);
                e.P_Name = item["P_Name"].ToString();

                list.Add(e);
            }
            ViewBag.Locality_id = new SelectList(list, "P_Id", "P_Name");
            return View();
        }
        public ActionResult GetLocality(string provice)
        {
            List<Province> list = new List<Province>();
            DataTable data = bll.GetLocality(provice);
            foreach (DataRow item in data.Rows)
            {
                Province e = new Province();
                e.P_Id = Convert.ToInt32(item["P_Id"]);
                e.P_Name = item["P_Name"].ToString();

                list.Add(e);
            }
            return Json(list, JsonRequestBehavior.AllowGet);
        }
        public ActionResult AddLocality(string dropDownListValue, string ss)
        {
            Province l = new Province();
            l.P_Name = ss;
            l.P_City = dropDownListValue;
            if (bll.AddLocality(l) > 0)
            {
                return Content("True");
            }
            else
            {
                return Content("Fales");
            }
        }

    }
}
